package com.david.dao;

import com.david.model.api.ArticleContent;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleContentDao {
    @Select("select * from articleContent where isDelete = 'false' ")
    List<ArticleContent> findAll();

    @Select("select * from articleContent where isDelete = 'false' and parentId = #{parentId} and type = #{type} order by sort desc,id desc")
    List<ArticleContent> findByparentIdType(@Param("parentId") Integer parentId, @Param("type") String type);

    @Select("select * from articleContent where id = #{id} and isDelete = 'false' ")
    ArticleContent findById(Integer id);

    @Update("update articleContent set isDelete = 1 where id = #{id} ")
    int delete(Integer id);

    @Update("update articleContent set title = #{title},imgSrc=#{imgSrc},content=#{content} where id = #{id}")
    int update(ArticleContent articleContent);

    @Insert("insert into articleContent (title,content,imgSrc,createTime,parentId,isDelete,type,sort) values (#{title},#{content},#{imgSrc},#{createTime},#{parentId},#{isDelete},#{type},#{sort})")
    int insert(ArticleContent articleContent);

    @Update("update articleContent set sort = #{sort} where id = #{id}")
    int updateSort(@Param("sort") Integer sort, @Param("id") Integer id);
}